<?php
include_once('common/header.php');
if($AppUI->id > 0) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$intHexUserId 		= $objRequest->getParam('phexuserid', 0);
$strExpireTime		= $objRequest->getParam('pexpiretime', '');
$strPassword		= $objRequest->getParam('prspassword', '');
$strPasswordConfirm	= $objRequest->getParam('prspassword_confirm', '');
$strCaptcha			= $objRequest->getParam('pcaptcha', '');
$intError	= 0;
if($strPassword == "" || $strPasswordConfirm == "" || $intHexUserId == "" || $strExpireTime == "" || $strCaptcha == "")
	$intError = 8;
elseif(!Vfriend_Captcha_Image::validate($strCaptcha)) {
	$intError = 2;
}
elseif(strlen($strPassword) < 8) {
	$intError = 11;
}
elseif($strPassword != $strPasswordConfirm) {
	$intError = 12;
}
if($intError == 0) {
	$objVfriendUser = new Vfriend_User();
	$objUser		= $objVfriendUser->getInfoByHexUserId($intHexUserId);
	if($objUser) {		
		$objVfriendUser->updatePassword($objUser->id, md5($strPassword), $objUser->email);
		Vfriend_Function::deleteCookie(COOKIE_VFRIEND_AUTH);
		$strSubject		= INDEX_NEW_PASSWORD_SUB;
		$this->view->strPassword = $strPassword;
		$this->view->objUser	 = $objUser;
		$objView 		= Zend_Registry::get('objView'); 
		$strContent 	= $objView->fetch('email/password.tpl');
		$objMail		= new Vfriend_Mail();
		$intSend		= $objMail->send(EMAIL_NOREPLY, EMAIL_NOREPLY_NAME, $objUser->email, $strSubject, $strContent);
		if($intSend) {
			Vfriend_Function::setMsg($arrMessage[1]);
			Vfriend_Function::redirect(HOST_VFRIEND);
		}
		else
			$intError = 3;		
	}
	else
		$intError 	= 13;
}
if($intError > 0) {
	$strHexUserId = Vfriend_Function::base64E($intHexUserId);
	Vfriend_Function::redirect(LINK_INDEX_RESET_PASSWORD . '?err=' . $intError . '&pu=' . $strHexUserId . '&pt=' . $strExpireTime);
}

?>